<?php
/**
 * IndexController
 * @author ComsenInc     
 * @copyright  Copyright (c)2007
 * @license
 */
class CategoryController extends Zend_Controller_Action {
    private $paper;
	function init(){
        $this->db = Zend_Registry::get('db');
        $this->smarty = Zend_Registry::get('smarty');
        $this->cache = Zend_Registry::get('cache');
        $this->smarty->assign('user',(array)Zend_Auth::getInstance()->getIdentity());
        Zend_Loader::loadClass('Threads');
        Zend_Loader::loadClass('Forums');
        Zend_Loader::loadClass('Forumfields');
        /*变量DIR为模板实际路径*/
        
        $this->smarty->assign('IMGDIR',$this->_request->getBaseUrl().'/'.$this->smarty->template_dir);
 
    }

	function indexAction(){
         $this->paper = (int)$this->_getParam('paper');
         if($this->paper == 0) { 
         	$this->paper = 1; 
         }
         $getfid = new Forums();
         $fid =$getfid ->category_boardnametofid($this->_getParam('action'));
         $this->smarty->assign('title',$fid['name']);
         $getforumfields = new Forumfields();
         $forumfields =$getforumfields ->category_getforumfields($fid['fid']);
         $category_threads = new Threads();
         
         $threads =$category_threads->category_thread($this->paper,$fid['fid'],'10','/Category/'.$this->_getParam('action').'/paper/');
         $this->smarty->assign('pagurl',$category_threads->pagurl);
         $this->smarty->assign('thread',$threads);
       	 $this->smarty->display('category.tpl');
	    
	}

	
	public function __call($method, $args)    
    {        
        if ('Action' == substr($method, -6)) 
        {            
            // If the action method was not found, forward to the index action
            //如果action方法没有找到,则转向到index action           
            return $this->_forward('index');        
        }        
        // all other methods throw an exception 
        //所有其他的方法则扔出一个错误信息  
        throw new Exception('Invalid method "' . $method . '" called');    
    }
    
    public function noRouterAction()
    {
        $this->_redirect('/');
    }
    
}